import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
    {
        path:'/goods',
        name:'HotelProducts',
        component:()=>import('../views/HotelProducts'),

    },
    {
        path:'/finance',
        name:'Finance',
        component:()=>import('../views/Finance'),
        meta:{
            keep:true
        }
    },
    {
        path:'/order',
        name:'Order',
        component:()=>import('../views/Order'),
        meta:{
            keep:true
        }
    },
    {
        path:'/dt',
        name:'DiningTable',
        component:()=>import('../views/DiningTable'),
        meta:{
            keep:true
        }
    },
  {
    path: '/',
    name: 'Login',
    component: () => import('../views/Login'),
      meta:{
        keep:false
      }
  },
    {
        path: '/home',
        name: 'Home',
        component: () => import('../views/Home'),
        meta:{
            keep:true
        }
    },
    {
        path: '/cashier',
        name: '餐饮收银台',
        component: () => import('../views/Cashier'),
        children: [
            {
                path: '/',
                name: 'order',
                component: () => import('../views/cashier/Order')
            },
            {
                path: '/takeMeal',
                name: 'takeMeals',
                component: () => import('../views/cashier/TakeMeals'),
            },
            {
                path: '/place',
                name: 'TablePlace',
                component: () => import('../views/cashier/table')
            },
            {
                path: '/row',
                name: 'RowNum',
                component: () => import('../views/cashier/RowNumber')
            },
            {
                path: '/clean',
                name: 'Clean',
                component: () => import('../views/cashier/Clean.vue')
            },
        ],
    },
  {
    path:'/food',
    name:'FoodManger',
    component:()=>import('../views/FoodManger.vue'),
      meta:{
          keep:true
      }
  },
    {
        path:'/staff',
        name:'StaffManger',
        component:()=>import('../views/StaffManger.vue'),
        meta:{
            keep:true
        }
    },
    {
        path:'/center',
        name:'Center',
        component:()=>import('../views/Center.vue'),
        meta:{
            keep:true
        }
    }
];


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});


// 路由守卫，开发不使用，用于前端验证登录状态
router.beforeEach(((to, from, next) => {
    if (to.path === '/'){
        next();
    }else {
        let token = localStorage.getItem('Authorization');
        console.log(token);
        if (token === null || token === ''){
            alert("您未登录或登录已过期,确认跳转登录界面");
            next('/')
        }else {
            next();
        }
    }
}));
export default router
